home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_069 / make / reader.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  110 lines

  1. /*
  2.  *    Read in makefile
  3.  */
  4.  
  5.  
  6. #include <stdio.h>
  7. #include    <ctype.h>
  8. #include "h.h"
  9.  
  10.  
  11. int             lineno;
  12.  
  13.  
  14. /*
  15.  *    Syntax error handler.  Print message, with line number, and exits.
  16.  */
  17. void
  18. error(msg, a1, a2, a3)
  19.     char           *msg;
  20. {
  21.     fprintf(stderr, "%s: ", myname);
  22.     fprintf(stderr, msg, a1, a2, a3);
  23.     if (lineno)
  24.     fprintf(stderr, " near line %d", lineno);
  25.     fputc('\n', stderr);
  26.     exit(1);
  27. }
  28.  
  29.  
  30. /*
  31.  *    Read a line into the supplied string of length LZ.  Remove
  32.  *    comments, ignore blank lines. Deal with    quoted (\) #, and
  33.  *    quoted newlines.  If EOF return TRUE.
  34.  */
  35. bool
  36. getline(str, fd)
  37.     char           *str;
  38.     FILE           *fd;
  39. {
  40.     register char  *p;
  41.     char           *q;
  42.     int             pos = 0;
  43.  
  44.  
  45.     for (;;) {
  46.     if (fgets(str + pos, LZ - pos, fd) == (char *) 0)
  47.         return TRUE;    /* EOF  */
  48.  
  49.     lineno++;
  50.  
  51.     if ((p = index(str + pos, '\n')) == (char *) 0)
  52.         error("Line too long");
  53.  
  54.     if (p[-1] == '\\') {
  55.         p[-1] = '\n';
  56.         pos = p - str;
  57.         continue;
  58.     }
  59.     p = str;
  60.     while (((q = index(p, '#')) != (char *) 0) &&
  61.            (p != q) && (q[-1] == '\\')) {
  62.         char           *a;
  63.  
  64.         a = q - 1;        /* Del \ chr; move rest back  */
  65.         p = q;
  66.         while (*a++ = *q++);
  67.     }
  68.     if (q != (char *) 0) {
  69.         q[0] = '\n';
  70.         q[1] = '\0';
  71.     }
  72.     p = str;
  73.     while (isspace(*p))    /* Checking for blank  */
  74.         p++;
  75.  
  76.     if (*p != '\0')
  77.         return FALSE;
  78.     pos = 0;
  79.     }
  80. }
  81.  
  82.  
  83. /*
  84.  *    Get a word from the current line, surounded by white space.
  85.  *    return a pointer to it. String returned has no white spaces
  86.  *    in it.
  87.  */
  88. char           *
  89. gettok(ptr)
  90.     char          **ptr;
  91. {
  92.     register char  *p;
  93.  
  94.  
  95.     while (isspace(**ptr))    /* Skip spaces  */
  96.     (*ptr)++;
  97.  
  98.     if (**ptr == '\0')        /* Nothing after spaces  */
  99.     return NULL;
  100.  
  101.     p = *ptr;            /* word starts here  */
  102.  
  103.     while ((**ptr != '\0') && (!isspace(**ptr)))
  104.     (*ptr)++;        /* Find end of word  */
  105.  
  106.     *(*ptr)++ = '\0';        /* Terminate it  */
  107.  
  108.     return (p);
  109. }
  110.